/****
 * 合并权限
 * ****/
export function setPermission(permissions) {
  // console.log(permissions)
  let permissionsList = []
  if(permissions.length > 1){         //多个权限列表需要合并checked值
    permissionsList = permissions[0].data
    for(var i = 1;i < permissions.length;i++){
      permissions[i].data.forEach((element,index) => {
        permissionsList[index].checked = permissionsList[index].checked || element.checked
      });
    }
    // console.log(permissionsList)
  }else{
    permissionsList = permissions[0].data
  }
  return permissionsList
}
/****
 * 校验权限
 * ****/
export function checkPermission(moduleName) {
  if (moduleName != null && moduleName != '') {
    const permissions = JSON.parse(sessionStorage.getItem('permissionsList'))
    var hasPermission = permissions.filter((item)=>{
      return item.code == moduleName
    })
    if (hasPermission.length == 0) {
      return false
    }
    return hasPermission[0].checked
  } else {
    console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
    return false
  }
}
